package com.bountytask.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.bountytask.dao.MessageDao;
import com.bountytask.entity.Message;
import com.bountytask.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;

import javax.xml.crypto.dsig.keyinfo.RetrievalMethod;
import java.util.HashMap;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    private MessageDao messageDao;
    /**
     * 添加留言信息
     */
    public JSONObject addOne(long userid,String mes){
        Message message = new Message();
        message.setMes(mes);
        message.setUserId(userid);
        int flag = messageDao.addOne(message);
        JSONObject resultJson = new JSONObject(true);
        JSONObject data = new JSONObject();
        data.put("id",message.getId());
        if(flag!=0){
            resultJson.put("code",200);
            resultJson.put("message","成功");
            resultJson.put("data",data);
            return resultJson;
        }
        resultJson.put("code",400);
        resultJson.put("message","失败");
        return resultJson;
    }
    /**
     * 查询留言id的信息
     */
    public Message getOne(long id){
        return messageDao.getOne(id);
    }
    /**
     * 查询全部留言信息
     * @return
     */
    public List<Message> getAll(){
        List<Message> list=messageDao.getAll();
        return list;
    }
}
